package com.caseprocessing.api;

import java.util.Map;

/**
 * 多模态内容部分
 * 支持文本和图像内容
 */
public class ContentPart {
    
    private String type;
    private String text;
    private Map<String, Object> imageUrl;
    
    public ContentPart() {}
    
    public ContentPart(String type, String text) {
        this.type = type;
        this.text = text;
    }
    
    public ContentPart(String type, Map<String, Object> imageUrl) {
        this.type = type;
        this.imageUrl = imageUrl;
    }
    
    /**
     * 创建文本内容部分
     */
    public static ContentPart text(String text) {
        return new ContentPart("text", text);
    }
    
    /**
     * 创建图像内容部分
     */
    public static ContentPart image(String imageUrl) {
        return new ContentPart("image_url", Map.of("url", imageUrl));
    }
    
    /**
     * 创建图像内容部分（带详细配置）
     */
    public static ContentPart image(String imageUrl, String detail) {
        return new ContentPart("image_url", Map.of("url", imageUrl, "detail", detail));
    }
    
    public String getType() {
        return type;
    }
    
    public void setType(String type) {
        this.type = type;
    }
    
    public String getText() {
        return text;
    }
    
    public void setText(String text) {
        this.text = text;
    }
    
    public Map<String, Object> getImageUrl() {
        return imageUrl;
    }
    
    public void setImageUrl(Map<String, Object> imageUrl) {
        this.imageUrl = imageUrl;
    }
    
    /**
     * 判断是否为文本类型
     */
    public boolean isText() {
        return "text".equals(type);
    }
    
    /**
     * 判断是否为图像类型
     */
    public boolean isImage() {
        return "image_url".equals(type);
    }
    
    /**
     * 获取图像URL
     */
    public String getImageUrlString() {
        if (imageUrl != null && imageUrl.containsKey("url")) {
            return (String) imageUrl.get("url");
        }
        return null;
    }
    
    @Override
    public String toString() {
        if (isText()) {
            return "ContentPart{type='text', text='" + text + "'}";
        } else if (isImage()) {
            return "ContentPart{type='image_url', imageUrl=" + imageUrl + "}";
        }
        return "ContentPart{type='" + type + "'}";
    }
}